#!/usr/bin/env python3
"""
修复 MinIO 配置
确保使用正确的域名而不是IP地址
"""
import re
import os

config_file = 'app/core/config.py'

print("🔧 开始修复 MinIO 配置...")

# 备份
if os.path.exists(config_file):
    with open(config_file, 'r', encoding='utf-8') as f:
        original = f.read()
    
    # 备份原文件
    with open(f'{config_file}.bak', 'w', encoding='utf-8') as f:
        f.write(original)
    print("✅ 已备份原配置文件")
    
    # 修改配置
    content = original
    
    # 1. 修改 MINIO_ENDPOINT
    content = re.sub(
        r'MINIO_ENDPOINT:\s*str\s*=\s*["\'].*?["\']',
        'MINIO_ENDPOINT: str = "minio.aqilmini.com"',
        content
    )
    
    # 2. 修改 MINIO_PUBLIC_URL  
    content = re.sub(
        r'MINIO_PUBLIC_URL:\s*str\s*=\s*["\'].*?["\']',
        'MINIO_PUBLIC_URL: str = "https://minio.aqilmini.com"',
        content
    )
    
    # 3. 确保 MINIO_SECURE 是 True
    content = re.sub(
        r'MINIO_SECURE:\s*bool\s*=\s*False',
        'MINIO_SECURE: bool = True',
        content
    )
    
    # 写回文件
    with open(config_file, 'w', encoding='utf-8') as f:
        f.write(content)
    
    print("✅ 配置文件修改完成")
    print("\n📝 修改的配置项：")
    print("   MINIO_ENDPOINT = 'minio.aqilmini.com'")
    print("   MINIO_PUBLIC_URL = 'https://minio.aqilmini.com'")
    print("   MINIO_SECURE = True")
    print("\n🔄 请重启后端服务：")
    print("   supervisorctl restart football_api")
else:
    print(f"❌ 找不到配置文件: {config_file}")
    print("   请确保在项目根目录执行此脚本")

